package com.example.liuling.oscbugly272;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.PowerManager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.tencent.bugly.crashreport.CrashReport;

public class MainActivity extends AppCompatActivity {
    private boolean iswakeLock = true;// 是否常亮
    private PowerManager.WakeLock wakeLock;

    private MyReceiver myReceiver = new MyReceiver();
    boolean isRegister = false;
    protected static final String ACTION = "com.lauren.broadcast.ACTION";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CrashReport.initCrashReport(getApplicationContext(), "900013488", false);
        setContentView(R.layout.activity_main);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentFilter filter = new IntentFilter();
                filter.addAction(ACTION);
                registerReceiver(myReceiver, filter);
                isRegister = true;
            }
        });

        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isRegister) {
                    unregisterReceiver(myReceiver);
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
    }


    private class MyReceiver extends BroadcastReceiver {

        private static final String TAG = "MyReceiver";

        public MyReceiver() {
            Log.i(TAG, "广播接收器的构造函数");
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i(TAG, "广播接收器接收到广播:"+intent.getAction());
        }

    }



}
